Rust で 線分 を描く(Rust製ラスタライザ)
目次
最終実装
最終実装
このページで実装したdraw_line関数を用いる。
code:rs
while window.is_open() && !window.is_key_down(Key::Escape) {
for i in 0..50 {
let theta = -PI/2.0 + (i as f64) * 2.0*PI / 50.0;
let r = (HEIGHT as f64) / 2.0;
let p1 = Point2::new((WIDTH as i32) / 2, (HEIGHT as i32) / 2);
let p2 = Point2::new(
(p1.x as f64 + r * f64::cos(theta)).floor() as i32,
(p1.y as f64 + r * f64::sin(theta)).floor() as i32
);
draw_line(&mut buffer, &p1, &p2, &Color::new(1., 1., 1.));
}
window.update_with_buffer(&buffer, WIDTH, HEIGHT)?;
}
https://scrapbox.io/files/66bb7596202bb3001d4cd0ce.png